# - Try to find Berkeley DB
# Once done this will define
#
#  BERKELEYDB_FOUND - system has Berkeley DB
#  BERKELEY_DB_INCLUDE_DIR - the Berkeley DB include directory
#  BERKELEY_DB_LIBRARIES - Link these to use Berkeley DB
#  BERKELEY_DB_DEFINITIONS - Compiler switches required for using Berkeley DB

message("BERKELEY_DB_PATH: ${BERKELEY_DB_PATH}")

if (BERKELEY_DB_PATH STREQUAL "")
    FIND_PATH(BERKELEY_DB_INCLUDE_DIR NAMES db_cxx.h)

    # FIND_LIBRARY(BERKELEY_DB_LIBRARIES NAMES db)
    FIND_LIBRARY(BERKELEY_DB_CXX_LIBRARIES NAMES db_cxx)
else ()
    FIND_PATH(BERKELEY_DB_INCLUDE_DIR NAMES db_cxx.h HINTS ${BERKELEY_DB_PATH}/include)

    # FIND_LIBRARY(BERKELEY_DB_LIBRARIES NAMES db HINTS ${BERKELEY_DB_PATH}/lib)
    FIND_LIBRARY(BERKELEY_DB_CXX_LIBRARIES NAMES libdb_cxx.a HINTS ${BERKELEY_DB_PATH}/lib)
endif ()

message("BERKELEY_DB_INCLUDE_DIR: ${BERKELEY_DB_INCLUDE_DIR}")
# message("BERKELEY_DB_LIBRARIES: ${BERKELEY_DB_LIBRARIES}")
message("BERKELEY_DB_CXX_LIBRARIES: ${BERKELEY_DB_CXX_LIBRARIES}")

MARK_AS_ADVANCED(BERKELEY_DB_INCLUDE_DIR BERKELEY_DB_CXX_LIBRARIES)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BerkeleyDB
        REQUIRED_VARS BERKELEY_DB_INCLUDE_DIR BERKELEY_DB_CXX_LIBRARIES)
# show the BERKELEY_DB_INCLUDE_DIR and BERKELEY_DB_LIBRARIES variables only in the advanced view
if (BERKELEYDB_FOUND)
    set(BERKELEY_DB_INCLUDE_DIRS ${BERKELEY_DB_INCLUDE_DIR})
    set(BERKELEY_DB_CXX_LIBRARY ${BERKELEY_DB_CXX_LIBRARIES})
endif ()

